import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import '@/assets/global.less'
// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
// 导入富文本编辑器的样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import axios from 'axios'
axios.defaults.baseURL = "http://big-event-vue-api-t.itheima.net"
axios.interceptors.request.use(function (config) {
  const {
    url
  } = config
  if (url.startsWith("/my")) {
    config.headers.Authorization = store.state.token
  }
  return config
}, function (error) {
  return Promise.reject(error)
})
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  return response;
}, function (error) {
  if (error.response.status === 401) {
    Vue.prototype.$message.error("请退出重新登录")
    store.commit('updateToken', '')
    router.push("/login")
  }
  // 对响应错误做点什么
  return Promise.reject(error);
});
// 导入全局样式表
Vue.prototype.$http = axios
Vue.use(ElementUI);
// 全局注册富文本编辑器
Vue.use(VueQuillEditor)
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
